<template>
  <div>
    <div class="list-table">
      <div class="area-header">
        <span class="area-header-title">{{ $t('基金Call款') }}</span>
      </div>
      <el-form ref="queryForm" :model="queryParams" :rules="queryParamsRules" :inline="true">
        <el-form-item v-if="!this.$route.query.id" :label="$t('基金名称')" prop="fundId">
          <MainBodySelect
            v-model="queryParams.fundId"
            parameters="fund"
            :disabled="this.$route.query.id"
          />
        </el-form-item>
        <el-form-item :label="$t('Call款期次')" prop="callPeriod">
          <el-input
            v-model="queryParams.callPeriod"
            :placeholder="$t('Call款期次')"
            clearable
            @keyup.enter.native="queryHandle"
          />
        </el-form-item>

        <el-form-item :label="$t('Call款时间')" prop="callDate">
          <DatePicker
            v-model="daterange"
            type="daterange"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            v-hasPermi="['fund:callmoney:edit']"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="addHandle"
          >{{ $t("新增") }}</el-button>
          <el-button
            v-hasPermi="['lp:LpPublicBulletin:edit']"
            type="success"
            size="mini"
            @click="setMessageTemplate"
          >{{ $t('通知内容模板') }}</el-button>
          <!--<el-button-->
          <!--  v-hasPermi="['system:word:edit']"-->
          <!--  type="warning"-->
          <!--  size="mini"-->
          <!--  @click="setTemplate"-->
          <!--&gt;{{ $t('通知文件模板') }}</el-button>-->
        </el-col>
        <!--<el-col :span="1.5">
          <el-button
            v-hasPermi="['fund:callmoney:export']"
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="exportHandle"
          >{{ $t("导出") }}</el-button>
        </el-col>-->
      </el-row>

      <el-table v-loading="fundCallMoneyLoading" tooltip-effect="darkTable" :show-summary="true" :summary-method="getSummaries" :data="fundCallMoneyList" border>
        <el-table-column type="index" align="center" show-overflow-tooltip width="45">
          <template slot-scope="scope">
            <el-radio v-model="radioView" :label="(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1" @change="choiceRadio(scope.$index, scope.row.fundId, scope.row.callPeriod)">
              <span style="display: none;" />
            </el-radio>
          </template>
        </el-table-column>
        <!--        <el-table-column :label="$t('序号')" align="center" show-overflow-tooltip width="50">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span class="link-type" @click="updateHandle(scope.row)">{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column v-if="!this.$route.query.id" :label="$t('基金名称')" header-align="center" align="left" class-name="text-align" show-overflow-tooltip prop="fundName" min-width="150" />
        <el-table-column :label="$t('Call款期次')" show-overflow-tooltip header-align="center" align="left" class-name="text-align" prop="callPeriod" min-width="120">
          <template slot-scope="scope">
            <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.callPeriod }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('Call款时间')" align="center" prop="callDate" :show-overflow-tooltip="true" min-width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.callDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('Call款金额') + $t('金额单位')" header-align="center" align="right" prop="callMoney" min-width="120">
          <template slot-scope="scope">
            <span class="money-text">{{ moneyFormat(scope.row.callMoney, 'w') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('通知Call款日期')" align="center" prop="noticeCallDate" min-width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.noticeCallDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('Call款截止日')" align="center" prop="callDateEnd" min-width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.callDateEnd) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('本次Call款占认缴比例(%)')" align="right" prop="thisCallProportion" min-width="150">
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.thisCallProportion, '') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('Call款进度(%)')" align="center" prop="payCallProportion" min-width="120">
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.payCallProportion, '') }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="useProcess" :label="$t('审批状态')" align="center" width="120">
          <template slot-scope="scope">
            <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" min-width="200">
          <template slot-scope="scope">
            <span style="display: none">{{ useProcess }}</span>
            <!-- 启动流程按钮 -->
            <div v-if="useProcess">
              <ListBtn v-if="useProcess" :bus-data="scope.row" has-permi="fund:callmoney">
                <template v-slot:before>
                  <el-button
                    v-if="(scope.row.actStatus === 'W' || scope.row.actStatus === 'D') && scope.row.announcementId"
                    size="small"
                    type="text"
                    icon="el-icon-s-promotion"
                    @click="noticeHandle(scope.row)"
                  >{{ $t('通知详情') }}</el-button>
                  <el-button
                    v-if="scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D' && scope.row.id !== undefined && scope.row.id !== null && scope.row.id !== ''"
                    v-hasPermi="['fund:callmoney:edit']"
                    size="small"
                    type="text"
                    icon="el-icon-s-tools"
                    @click="sendHandle(scope.row, scope.$index)"
                  >{{ $t('通知配置') }}</el-button>
                </template>
              </ListBtn>
            </div>
            <!-- 未启动流程按钮 -->
            <div v-if="!useProcess">
              <el-button
                v-if="(scope.row.announcementId) && (scope.row.status === '已发送')"
                size="small"
                type="text"
                icon="el-icon-s-promotion"
                @click="noticeHandle(scope.row)"
              >{{ $t('通知详情') }}</el-button>
              <el-button
                v-if="(scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D' && scope.row.id !== undefined && scope.row.id !== null && scope.row.id !== '') && (scope.row.status === '待复核')"
                v-hasPermi="['fund:callmoney:edit']"
                size="small"
                type="text"
                icon="el-icon-s-tools"
                @click="noticeHandle(scope.row)"
              >{{ $t('复核通知') }}</el-button>
              <el-button
                v-if="(scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D' && scope.row.id !== undefined && scope.row.id !== null && scope.row.id !== '') && (scope.row.status !== '待复核' && scope.row.status !== '已发送')"
                v-hasPermi="['fund:callmoney:edit']"
                size="small"
                type="text"
                icon="el-icon-s-tools"
                @click="sendHandle(scope.row, scope.$index)"
              >{{ $t('发送通知') }}</el-button>
              <el-button
                v-if="!useProcess"
                v-hasPermi="['fund:callmoney:edit']"
                size="small"
                type="text"
                icon="el-icon-edit"
                @click="updateHandle(scope.row)"
              >{{ $t('修改') }}</el-button>
              <el-button
                v-if="!useProcess"
                v-hasPermi="['fund:callmoney:remove']"
                :disabled="scope.row.buttonDisabledState"
                size="small"
                type="text"
                icon="el-icon-delete"
                @click="deleteHandle(scope.row)"
              >{{ $t('删除') }}</el-button>
              <span style="display: none">{{ scope.row.announcementId }}</span>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改基金Call款对话框 -->
      <el-dialog :title="$t('基金Call款')" :visible.sync="formCallOpen" :close-on-click-modal="false" :destroy-on-close="true" :lock-scroll="false" custom-class="dialogForm" append-to-body>
        <fundCallMoneyForm ref="fundCallMoneyForm" />
      </el-dialog>

      <el-dialog :title="$t('公示内容')" :visible.sync="publicityOpen" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
        <afficheForm v-if="publicityOpen" ref="afficheForm" parent-business-type="callMoney" :call-init-status="callInitStatus" :call-money-use-process="useProcess" :show-save-btn="showAfficheSaveBtn" @notNullAfffiche="notNullAfffiche" />
      </el-dialog>

      <el-dialog :title="$t('公告审核')" :visible.sync="emailReviewOpen" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
        <emailReviewForm v-if="emailReviewOpen" ref="emailReviewForm" :show-btn-status="!useProcess" />
      </el-dialog>

    </div>

    <!--Call款明细-->
    <div v-if="isShowDetails === 'show'" v-loading="loading" class="list-table" style="margin-top: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('Call款明细') }}</span>
        <div style="float: right;font-size: 15px;">
          <el-button type="info" size="mini" @click="batchDownloadCallNotifications">
            {{ $t('通知批量下载') }}
          </el-button>
          <el-button type="primary" size="mini" :disabled="batchPaymentStatus" @click="bulkPayment">
            {{ $t('批量缴款') }}
          </el-button>
          <el-button type="danger" size="mini" @click="hiddenDetails">
            {{ $t('关闭') }}
          </el-button>
        </div>
      </div>
      <el-table :data="fundCallMoneyDetailList" tooltip-effect="darkTable" :show-summary="true" :summary-method="getDetailSummaries" border class="nowrapTable formTable">
        <el-table-column align="center" prop="investName" show-overflow-tooltip min-width="150">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('出资人名称') }}</span><i class="el-icon-question" :title="$t('出资人名称')" /></span>
          </template>
          <template slot-scope="scope">
            {{ scope.row.investName }}
          </template>
        </el-table-column>
        <el-table-column prop="payMoney" align="center" class-name="detail" show-overflow-tooltip width="120">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('认缴金额') }}{{ $t('金额单位') }}</span><i class="el-icon-question" :title="$t('出资人认缴金额')" /></span>
          </template>
          <template slot-scope="scope">
            {{ moneyFormat(scope.row.payMoney, 'w') }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('认缴比例(%)')" align="center" class-name="detail" prop="payProp" show-overflow-tooltip width="110">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('认缴比例') }}</span><i class="el-icon-question" :title="$t('当前基金所有出资人认缴总额占比')" /></span>
          </template>
          <template slot-scope="scope">
            {{ (scope.row.payProp * 100).toFixed(2) }}%
          </template>
        </el-table-column>
        <el-table-column :label="$t('实缴总额')" align="center" class-name="detail" show-overflow-tooltip width="130">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('实缴总额') }}{{ $t('金额单位') }}</span><i class="el-icon-question" :title="$t('实际缴款总金额')" /></span>
          </template>
          <template slot-scope="scope">
            {{ moneyFormat(scope.row.accumulatedAmountPid, 'w') }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('累计Call款金额')" align="center" class-name="detail" prop="sumCallMoney" show-overflow-tooltip width="140">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('累计Call款金额') }}{{ $t('金额单位') }}</span><i class="el-icon-question" :title="$t('本次缴款前的应缴金额总和 (本次缴款不参与计算)')" /></span>
          </template>
          <template slot-scope="scope">
            {{ moneyFormat(scope.row.sumCallMoney, 'w') }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('剩余认缴金额')" align="center" class-name="detail" prop="surplusMoney" show-overflow-tooltip width="130">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('剩余认缴金额') }}{{ $t('金额单位') }}</span><i class="el-icon-question" :title="$t('认缴金额 - 本次缴款前的实缴总额 (本次缴款不参与计算)')" /></span>
          </template>
          <template slot-scope="scope">
            {{ moneyFormat(scope.row.surplusMoney, 'w') }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('剩余应缴金额')" align="center" class-name="detail" show-overflow-tooltip width="130">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('剩余应缴金额') }}{{ $t('金额单位') }}</span><i class="el-icon-question" :title="$t('本次应缴金额 - 本次已缴款金额')" /></span>
          </template>
          <template slot-scope="scope">
            {{ moneyFormat(scope.row.remainingSubscription, 'w') }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('本次应缴金额')" align="center" class-name="detail" show-overflow-tooltip width="130">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('本次应缴金额') }}{{ $t('金额单位') }}</span><i class="el-icon-question" :title="$t('本次应缴金额')" /></span>
          </template>
          <template slot-scope="scope">
            {{ moneyFormat(scope.row.thisCallMoney, 'w') }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('本次已缴金额')" align="center" class-name="detail" show-overflow-tooltip width="130">
          <template slot="header" slot-scope="{}">
            <span class="flex"><span>{{ $t('本次已缴金额') }}{{ $t('金额单位') }}</span><i class="el-icon-question" :title="$t('本次应缴金额 - 剩余应交金额')" /></span>
          </template>
          <template slot-scope="scope">
            {{ moneyFormat(scope.row.thisCallMoney - scope.row.remainingSubscription, 'w') }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('操作')" align="center" fixed="right" width="200">
          <template slot-scope="scope">
            <el-button
              size="small"
              icon="el-icon-document"
              type="text"
              calss="el-button el-button--primary el-button--mini"
              @click="generateCallNotice(scope.row)"
            >{{ $t('下载Call款通知') }}</el-button>
            <el-button
              size="small"
              icon="el-icon-edit-outline"
              type="text"
              calss="el-button el-button--primary el-button--mini"
              :disabled="scope.row.buttonStatus"
              @click="contribution(scope.row)"
            >{{ $t('缴款') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 添加或修改出资人缴款对话框 -->
    <el-dialog :title="$t('出资人缴款')" :visible.sync="fundLpPaymentLoading" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundLpPaymentForm ref="fundLpPaymentForm" />
    </el-dialog>
    <!-- 批量缴款-->
    <el-dialog :title="batchPaymentTitle" :visible.sync="fundBulkPaymentLoading" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundBulkPayment ref="fundBulkPayment" />
    </el-dialog>
    <!-- 模板列表 -->
    <el-dialog :title="keyWordTitle" :visible.sync="keyWordLoading" :close-on-click-modal="false" custom-class="dialogForm" append-to-body>
      <wordOnlineTemplateList ref="wordOnlineTemplateList" @saveSelectTemplate="saveSelectTemplate" />
    </el-dialog>

    <!-- 模板form页面 -->
    <div>
      <div v-show="keyWordFormLoading" style="text-align: center">
        <i class="el-icon-loading" style="font-size: 30px;color: #ffffff;z-index: 6002 !important;position: absolute;margin-top: -20vh;" />
        {{ $t('正在生成各出资人的文档') }}
      </div>
      <el-dialog :title="keyWordTitle" :visible.sync="keyWordFormLoading" width="600px" :close-on-click-modal="false" custom-class="dialogForm dialogFormCustom" append-to-body>
        <wordOnlineTemplateForm ref="wordOnlineTemplateForm" @templateFormCancel="templateFormCancel" />
      </el-dialog>
    </div>

    <el-dialog :title="$t('模板维护')" :visible.sync="templateOpen" :destroy-on-close="true" :close-on-click-modal="false" custom-class="dialogForm" append-to-body>
      <afficheTemplateForm v-if="templateOpen" ref="afficheTemplateForm" parent-template-type="callMoney" />
    </el-dialog>
  </div>
</template>

<script>
import wordOnlineTemplateForm from '@/views/system/word/template/wordOnlineTemplateForm.vue'
import wordOnlineTemplateList from '@/views/system/word/template/wordOnlineTemplateList.vue'
import afficheTemplateForm from '@/views/fund/lpBase/lp/afficheTemplateForm'
import afficheForm from '@/views/fund/lpBase/lp/afficheForm.vue'
import fundCallMoneyForm from './fundCallMoneyForm.vue'
import fundLpPaymentForm from '@/views/fund/lpPayment/fundLpPaymentForm'
import fundBulkPayment from '@/views/fund/callmoney/fundBulkPayment'
import MainBodySelect from '@/components/MainBodySelect/index'
import emailReviewForm from '@/views/fund/lpBase/lp/EmailReviewForm'
import {
  listFundCallMoney,
  delFundCallMoney,
  getFindCallDetails, getFundCallMoneySum
} from '@/api/fund/callmoney/fundCallMoney'
import { findLpViewGetInvest } from '@/api/fund/investor/fundInvestor'
import { downLoadExcel } from '@/utils/excelDownload'
import { saveWordSetCustomTemplate, checkIsTemplate } from '@/api/system/word/template/wordOnlineTemplate'
import { downLoadFileOpen } from '@/utils/zipdownload.js'
import { getMenuProcess } from '@/api/act/process/wfMenuProcess'
import { existBusinessId } from '@/api/fund/lpBase/lp/affiche/afficheListTemplate'
import { getFundBase } from '@/api/fund/fundBase'
export default {
    components: {
      emailReviewForm,
      afficheForm,
      afficheTemplateForm,
      fundCallMoneyForm,
      fundLpPaymentForm,
      fundBulkPayment,
      MainBodySelect,
      wordOnlineTemplateList,
      wordOnlineTemplateForm
    },
  data() {
    return {
      radioView: '0',
      // 遮罩层
      loading: true,
      fundLpPaymentLoading: false,
      fundCallMoneyLoading: true,
      fundBulkPaymentLoading: false,
      // 总条数
      total: 0,
      // 基金Call款表格数据
      fundCallMoneyList: [],
      fundCallMoneySum: [],
      // 弹出层标题
      title: undefined,
      generateCallNoticeOpen: false,
      // 是否显示弹出层
      formCallOpen: false,
      publicityOpen: false,
      emailReviewOpen: false,
      // 点击选择Call款时   所选Call款的基金ID
      selectCallFundId: undefined,
      // 点击选择Call款时   所选Call款的index
      selectCallIndex: undefined,
      // 查询参数
      queryParams: {
        callPeriod: undefined,
        callDate: undefined,
        callMoney: undefined,
        fundId: this.$route.query.id ? this.$route.query.id : undefined,
        pageNum: 1,
        pageSize: 10
      },
      queryParamsRules: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 是否配置了流程
      useProcess: false,
      // 公告按钮可见
      showAfficheSaveBtn: true,
      // 时间区间
      daterange: [],
      currencyOptions: [],
      fundCallMoneyDetailList: [],
      // 是否显示 call明细
      isShowDetails: undefined,
      // 批量缴款页面标题
      batchPaymentTitle: '',
      // 当前选中的要Call款的期次名称
      callPeriodName: '',
      // 模板列表
      keyWordTitle: '',
      keyWordLoading: false,
      menuKey: 'fund_investor_call',
      keyWordFormLoading: false,
      batchPaymentStatus: false,
      templateOpen: false,
      callInitStatus: true
    }
  },
  created() {
    this.getUseProcess()
    this.getList()
    // // 付款币种
    // this.getDicts('currency').then(response => {
    //   this.currencyOptions = response.data
    // })
  },
  methods: {
    /** 查询基金Call款列表 */
    getList() {
      this.fundCallMoneyLoading = true
      this.hiddenDetails()
      getFundCallMoneySum(this.addDateRange(this.queryParams, this.daterange)).then(res => {
        this.fundCallMoneySum = res.data
      })
      listFundCallMoney(this.addDateRange(this.queryParams, this.daterange)).then(response => {
        this.fundCallMoneyList = response.rows
        this.total = response.total
        this.fundCallMoneyLoading = false
      })
    },
    // currencyFormat(row) {
    //   return this.selectDictLabel(this.currencyOptions, row.currency)
    // },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        callPeriod: undefined,
        callType: undefined,
        callDate: undefined,
        callMoney: undefined,
        noticeCallDate: undefined,
        callDateEnd: undefined,
        fundTotalSubscription: undefined,
        currency: undefined,
        thisCallProportion: undefined,
        payCallProportion: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterange = []
      this.resetForm('queryForm')
      this.queryHandle()
    },
    // 审核公告
    noticeHandle(row) {
      this.emailReviewOpen = true
      this.$nextTick(() => {
        this.$refs.emailReviewForm.init({ id: row.announcementId })
      })
    },
    // 配置公告
    sendHandle(row, index) {
      this.callInitStatus = true
      this.showAfficheSaveBtn = !(row.actStatus === 'W' || row.actStatus === 'D')
      this.publicityOpen = true
      this.$nextTick(() => {
        if (row.announcementId !== undefined && row.announcementId !== null && row.announcementId !== '') {
          // 判断当前基金是否存在模板不存在取默认的
          var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
          fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
          existBusinessId({ businessId: fundId, businessType: 'callMoney', orgId: '3' }).then(response => {
            if (response.data) {
              this.$refs.afficheForm.init({ id: row.announcementId, fundId: row.fundId, type: response.data.id, callPeriod: row.callPeriod, dataId: row.id })
            } else {
              this.$refs.afficheForm.init({ id: row.announcementId, fundId: row.fundId, type: '3', callPeriod: row.callPeriod, dataId: row.id })
            }
          })
        } else {
          this.updateSendHandle(row)
        }
        this.choiceRadio(index, row.fundId, row.callPeriod)
      })
    },
    updateSendHandle(row) {
      // 判断当前基金是否存在模板不存在取默认的
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      existBusinessId({ businessId: fundId, businessType: 'callMoney', orgId: '3' }).then(response => {
        if (response.data) {
          this.$refs.afficheForm.reset()
          this.$refs.afficheForm.form.fundId = row.fundId
          this.$refs.afficheForm.form.callPeriod = row.id
          this.$refs.afficheForm.form.type = response.data.id
          this.$refs.afficheForm.dataChange(row.fundId)
        }
      })
    },
    notNullAfffiche(row) {
      this.publicityOpen = false
      setTimeout(() => {
        this.callInitStatus = true
        this.publicityOpen = true
        this.$nextTick(() => {
          row.id = row.dataId
          this.updateSendHandle(row)
        })
      }, 100)
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formCallOpen = true
      this.$nextTick(() => {
        this.$refs.fundCallMoneyForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formCallOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.fundCallMoneyForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delFundCallMoney(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    /** 导出按钮操作 */
    exportHandle() {
      downLoadExcel('/callmoney/fundCallMoney/export', this.queryParams)
    },
    choiceRadio(index, fundId, callPeriod) {
      this.loading = true
      this.callPeriodName = callPeriod
      this.selectCallFundId = fundId
      this.selectCallIndex = index
      this.isShowDetails = 'show'
      this.fundCallMoneyDetailList = []
      this.queryParams.fundId = fundId
      getFindCallDetails(this.fundCallMoneyList[index].id, fundId).then(response => {
        response.data.forEach(item => {
          var callDateEnd = this.fundCallMoneyList[index].callDateEnd
          if (callDateEnd === undefined || callDateEnd === null) {
            callDateEnd = new Date()
          }
          const row = {
            id: item.id,
            fundCallMoneyId: item.fundCallMoneyId,
            investId: item.investId,
            investName: item.investName,
            // 认缴金额 payMoney
            payMoney: item.payMoney.toFixed(2),
            // 认缴比例 payProp
            payProp: item.payProp.toFixed(6),
            // 剩余认缴金额 surplusMoney   // 认缴 - 历史Call款
            surplusMoney: item.surplusMoney,
            // 累计Call款金额 sumCallMoney // 历史Call款
            sumCallMoney: item.sumCallMoney,
            // 实缴总额
            accumulatedAmountPid: item.accumulatedAmountPid === null ? 0 : item.accumulatedAmountPid,
            // 剩余应缴金额
            remainingSubscription: item.thisCallMoney - item.remainingSubscription,
            // 本次应缴金额
            thisCallMoney: item.thisCallMoney,
            // 按钮是否禁用
            buttonStatus: item.buttonStatus,
            // 截止日期
            callDateEnd: callDateEnd
          }
          this.$nextTick(() => {
            this.fundCallMoneyDetailList.push(row)
          })
        })
        this.$nextTick(() => {
          var flag = true
          this.fundCallMoneyDetailList.some(item => {
            if (!item.buttonStatus) {
              flag = false
              return true
            }
          })
          console.log(flag)
          this.batchPaymentStatus = flag
        })
        this.loading = false
      })
    },
    hiddenDetails() {
      this.radioView = '0'
      this.isShowDetails = ''
    },
    // 批量缴款
    bulkPayment() {
      this.fundBulkPaymentLoading = true
      // 获取Call款期次名称
      this.getNameOfCallPeriod()
      this.batchPaymentTitle = this.$t('批量缴款 (Call款期次: {callPeriodName})', { callPeriodName: this.callPeriodName })
      this.$nextTick(() => {
        this.$refs.fundBulkPayment.init(this.fundCallMoneyDetailList, this.fundCallMoneyList[this.selectCallIndex], this.selectCallIndex)
      })
    },
    // 获取Call款期次名称
    getNameOfCallPeriod() {
      const detail = this.fundCallMoneyDetailList
      if (detail !== null && detail !== undefined && detail !== '' && detail.length > 0) {
        const detailOne = detail[0]
        this.fundCallMoneyList.forEach(item => {
          if (item.id === detailOne.fundCallMoneyId) {
            this.callPeriodName = item.callPeriod
          }
        })
      }
      console.log()
    },
    contribution(row) {
      console.log('缴款')
      this.fundLpPaymentLoading = true
      this.$nextTick(() => {
        this.$refs.fundLpPaymentForm.init(null)
        // 出资人名称
        findLpViewGetInvest(row.investId, this.selectCallFundId).then(response => {
          this.$refs.fundLpPaymentForm.form.investId = response.data.id
          this.$refs.fundLpPaymentForm.initData(this.selectCallFundId)
          this.$refs.fundLpPaymentForm.form.fundId = this.selectCallFundId
          // 截止日
          this.$refs.fundLpPaymentForm.form.callDateEnd = row.callDateEnd
          // 出资人和Call款期次不可选
          this.$refs.fundLpPaymentForm.investIdDisabledStatus = true
          // 期次
          this.$refs.fundLpPaymentForm.form.callPeriod = row.fundCallMoneyId
          // 认缴
          this.$refs.fundLpPaymentForm.form.subscriptionAmount = row.payMoney
          // Call款金额
          this.$refs.fundLpPaymentForm.form.callMoney = row.thisCallMoney
          // 已缴金额
          this.$refs.fundLpPaymentForm.form.amountPaid = row.thisCallMoney - row.remainingSubscription
          // 剩余金额
          this.$refs.fundLpPaymentForm.form.amountRemaining = row.remainingSubscription
          // 本次应缴金额 带到 缴款金额
          try {
            this.$refs.fundLpPaymentForm.form.payMoney = row.remainingSubscription
          } catch (e) {
            console.log(e)
          }
          this.$refs.fundLpPaymentForm.isShowCallInfo = true
          this.$refs.fundLpPaymentForm.fundCallMoneyIndex = this.selectCallIndex
        })
      })
    },
    toFixedNumber(value, count) {
      if (value === undefined) {
        return 0
      }
      value = value.replaceAll(',', '')
      return parseFloat(Number(value).toFixed(count))
    },
    // 生成Call款通知
    generateCallNotice(row) {
      console.log(row)
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      checkIsTemplate(fundId, 'fund', 'JJCALLKTZ').then(response => {
        if (response.data === null) {
          this.msgError(this.$t('请先设置模板!'))
        } else {
          this.downloadTemplate(response.data, row, fundId)
        }
      })
    },
    // 下载Call款模板文件
    downloadTemplate(data, row, fundId) {
      console.log('下载模板')
      this.keyWordTitle = '生成Call款模板'
      this.keyWordFormLoading = true
      this.$nextTick(() => {
        this.$refs.wordOnlineTemplateForm.initCallMoney(data, row, fundId)
      })
    },
    // 基金Call款专用, 生成Call款通知
    async generateCallNoticeByFundCall(that, row, callBack) {
      console.log(row)
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      await checkIsTemplate(fundId, 'fund', 'JJCALLKTZ').then(response => {
        if (response.data === null) {
          that.LpBulletinInvestorLoading = false
          this.msgError(this.$t('请先设置模板!'))
        } else {
          this.downloadTemplateByFundCall(response.data, row, fundId, callBack)
        }
      })
    },
    downloadTemplateByFundCall(data, row, fundId, callBack) {
      this.keyWordFormLoading = true
      this.$nextTick(() => {
        this.$refs.wordOnlineTemplateForm.initCallMoneyByFundCall(data, row, fundId, callBack)
      })
    },
    // 通知模板
    setMessageTemplate() {
      this.templateOpen = true
      this.$nextTick(() => {
        // 判断当前基金是否存在模板不存在取默认的
        var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
        fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
        existBusinessId({ businessId: fundId, businessType: 'callMoney', orgId: '3' }).then(response => {
          if (response.data) {
            this.$refs.afficheTemplateForm.init({ id: response.data.id })
          } else {
            this.$refs.afficheTemplateForm.init({ id: '3' })
          }
        })
      })
    },
    // 设置模板
    setTemplate() {
      console.log('打开模板列表')
      this.queryParamsRules.fundId = []
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      if (fundId) {
        this.keyWordLoading = true
        this.keyWordTitle = this.$t('模板列表')
        this.$nextTick(() => {
          this.$refs.wordOnlineTemplateList.textReminder = '模板中必须包含 "&{出资人名称}" 关键字'
          this.$refs.wordOnlineTemplateList.queryParams.templateType = 'JJCALLKTZ'
          this.$refs.wordOnlineTemplateList.externalCallTemplateStatus = true
          this.$refs.wordOnlineTemplateList.getList()
        })
      } else {
        this.queryParamsRules.fundId = [{ required: true, message: this.$t('先选择一支基金'), trigger: ['change', 'blur'] }]
        this.$refs['queryForm'].validate()
      }
    },
    // 保存选定的模板
    saveSelectTemplate(that, row) {
      console.log(row)
      that.loading = true
      const type = that.queryParams.templateType
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      saveWordSetCustomTemplate({ businessId: fundId, businessType: 'fund', templateId: row.id, keyWord: row.customValue, templateType: type }).then(response => {
        if (response.code === 200) {
          this.msgSuccess(response.msg)
          // 关闭页面
          this.keyWordLoading = false
        } else {
          this.msgError(response.msg)
        }
        that.loading = false
      })
    },
    // 关闭模板form页面
    templateFormCancel() {
      this.keyWordFormLoading = false
    },
    // 获取是否使用流程
    getUseProcess() {
      // 根据基金ID区分使用基金流程还是SPV流程
      getFundBase(this.$route.query.id).then(res => {
        if (res && !this.isEmpty(res.data)) {
          if (res.data.dataType === 'spv' || res.data.dataType === 'SPV') {
            this.menuKey = 'fund_investor_call_spv'
          }
        }
        getMenuProcess(this.menuKey).then(response => {
          this.useProcess = (response.data !== undefined && response.data !== null && response.data !== '')
        })
      })
    },
    // 批量下载Call款模板
    batchDownloadCallNotifications() {
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      checkIsTemplate(fundId, 'fund', 'JJCALLKTZ').then(response => {
        if (response.data === null) {
          this.msgError(this.$t('请先设置模板!'))
        } else {
          console.log('下载模板')
          this.keyWordTitle = '生成Call款模板'
          this.keyWordFormLoading = true
          this.$nextTick(() => {
            this.$refs.wordOnlineTemplateForm.templatePackagePathArr = []
            this.$refs.wordOnlineTemplateForm.templatePackagePathSendCount = this.fundCallMoneyDetailList.length
            this.fundCallMoneyDetailList && this.fundCallMoneyDetailList.forEach((row) => {
              this.$refs.wordOnlineTemplateForm.initCallMoneyBatch(response.data, row, fundId)
            })
          })
        }
      })
    },
    // wordOnlineTemplateForm 页面会调用该方法. 这里记录一下生成的模板文件存放路径 然后去后台将这些文件打包并下载
    templatePackageDownload(data, that) {
      console.log(data)
      if (data) {
        downLoadFileOpen('/word/wordOnlineTemplate/templatePackageDownload?data=' + encodeURIComponent(data.join(',')))
        // 关闭生成页面的遮盖层
        that.dataLoading = false
        // 关闭生成页面
        this.keyWordFormLoading = false
      } else {
        this.msgError('生成错误!')
      }
    },
    // 合计
    getSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 1) {
          sums[index] = '合计'
        } else if (index === 3) {
          sums[index] = this.moneyFormat(this.fundCallMoneySum.callMoney, 'w')
        } else if (index === 6) {
          sums[index] = this.fundCallMoneySum.thisCallProportion
        } else {
          sums[index] = ''
        }
      })
      return sums
    },
    getDetailSummaries(param) {
      let payMoney = 0
      let payProp = 0
      let accumulatedAmountPid = 0
      let sumCallMoney = 0
      let surplusMoney = 0
      let remainingSubscription = 0
      let thisCallMoney = 0
      this.fundCallMoneyDetailList.forEach((item) => {
        if (item.payMoney) {
          payMoney += Number(item.payMoney)
        }
        if (item.payProp) {
          payProp += Number(item.payProp)
        }
        if (item.accumulatedAmountPid) {
          accumulatedAmountPid += Number(item.accumulatedAmountPid)
        }
        if (item.sumCallMoney) {
          sumCallMoney += Number(item.sumCallMoney)
        }
        if (item.surplusMoney) {
          surplusMoney += Number(item.surplusMoney)
        }
        if (item.remainingSubscription) {
          remainingSubscription += Number(item.remainingSubscription)
        }
        if (item.thisCallMoney) {
          thisCallMoney += Number(item.thisCallMoney)
        }
      })
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index === 1) {
          sums[index] = this.moneyFormat(payMoney, 'w')
        } else if (index === 2) {
          sums[index] = payProp.toFixed(2) * 100
        } else if (index === 3) {
          sums[index] = this.moneyFormat(accumulatedAmountPid, 'w')
        } else if (index === 4) {
          sums[index] = this.moneyFormat(sumCallMoney, 'w')
        } else if (index === 5) {
          sums[index] = this.moneyFormat(surplusMoney, 'w')
        } else if (index === 6) {
          sums[index] = this.moneyFormat(remainingSubscription, 'w')
        } else if (index === 7) {
          sums[index] = this.moneyFormat(thisCallMoney, 'w')
        } else if (index === 8) {
          sums[index] = this.moneyFormat(thisCallMoney - remainingSubscription, 'w')
        } else {
          sums[index] = ''
        }
      })
      sums.push(' ')
      return sums
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  .flex{
    display: flex;
    align-items: center;
    line-height: 16px;
    justify-content: center;
    span{
      max-width: 90%;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  /deep/.dialogFormCustom {
    display: none;
  }
  /deep/.el-table__footer-wrapper .text-align .cell {
    text-align: center!important;
  }
  /deep/.el-table .el-table__footer-wrapper .detail .cell {
    text-align: center!important;
  }
</style>
